package com.erainm.server_monitor;

import org.I0Itec.zkclient.ZkClient;

public class ServerMain {

    private ZkClient zkClient = null;

    // 获取到zk对象
    private void connectZK(){
        zkClient = new ZkClient("lg01:2181,lg02:2181,lg03:2181");
        if (!zkClient.exists("/servers")){
            zkClient.createPersistent("/servers");
        }
    }

    // 注册服务端信息到zk节点
    private void registerServerInfo(String ip,String port){
        // 创建临时顺序节点
        final String path = zkClient.createEphemeralSequential("/servers/server",ip + ":" + port);
        System.out.println("---->>> 服务器器注册成功，ip="+ip+";port ="+port+";节点路径信息="+path);
    }

    public static void main(String[] args) {
        ServerMain server = new ServerMain();
        server.connectZK();

        server.registerServerInfo(args[0],args[1]);

        // 启动一个服务线程提供时间查询
        new TimeServer(Integer.parseInt(args[1])).start();
    }


}
